import time


def reader(flname):
    fl = open(flname)
    data = fl.readlines()
    data = [int(i) for i in data]
    return data
m1 = reader('m1_sorted.txt')
m2 = reader('m2_reverse.txt')
m3 = reader('m3_shuffle.txt')
def bubble_sort(arr):
    for i in range(0, len(arr) - 1):
        all_sorted = True
        for j in range(0, len(arr) - i - 1):
            if arr[j] > arr[j + 1]:
                all_sorted = False
                arr[j + 1], arr[j] = arr[j], arr[j + 1]
        if all_sorted:
            return
t_start_m1 = time.time()
bubble_sort(m1)
t_finish_m1 = time.time()
time_m1 = round((t_finish_m1 - t_start_m1) * 1000)
print(f'm1_sorted {time_m1} milliseconds')
t_start_m2 = time.time()
bubble_sort(m2)
t_finish_m2 = time.time()
time_m2 = round((t_finish_m2 - t_start_m2) * 1000)
print(f'm2_reversed {time_m2} milliseconds')
t_start_m3 = time.time()
bubble_sort(m3)
t_finish_m3 = time.time()
time_m3 = round((t_finish_m3 - t_start_m3) * 1000)
print(f'm3_shuffle.txt {time_m3} milliseconds')